import Vue from "vue";
import Router from "vue-router";
import Layout from "../views/layout/Index.vue";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
import commonRoutes from "./commonRoutes";
import businessRoutes from "./businessRoutes";
Vue.use(Router);
const router = new Router({
  base: "/",
  scrollBehavior: () => ({
    y: 0
  }),
  routes: [
    // 默认页面
    {
      path: "/",
      redirect: "/demo"
    },
    {
      path: "/admin",
      component: Layout,
      children: businessRoutes
    },
    ...commonRoutes
  ]
});
router.beforeEach((to, from, next) => {
  NProgress.start();
  next();
});
router.afterEach(() => {
  NProgress.done();
});
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};
export default router;
